<?php
/**
 * 给微信用户打标签
 * @author panchenxing@star-net.cn
 * @version $Id: Email.php 3 2017-06-27 03:02:47Z chendanming $
 */

namespace app\console\swooletask\logic;


use app\wechat\service\WechatBase;
use think\Log;
use app\wechat\service\Wechat;

class WechatTag {

    /**
     * 给微信用户打标签
     * @param $wechat
     * @return array
     */
    public function wechatTag($wechat){
//        Log::record(['more_info' => ['swoole_server_onreceive'=>json_encode($wechat)]], 'elk');
//        Log::save();
        $wechatService = new Wechat();
        //如果不是其他标签，先取消用户身上的其他标签(161)
        if($wechat['tagid'] != 161){
            $ret = $wechatService->batchuntagging($wechat['openid'],161);
            if($ret['errcode'] > 0){
                Log::record(json_encode(['swoole_server_error_data'=>$wechat]), 'elk_more_info','wechat_tag');
                Log::record(json_encode(['swoole_server_error_return'=>$ret]), 'elk_more_info','wechat_tag');
                //Log::save();
            }
        }

        //打标签
        $res = $wechatService->batchTagging($wechat['openid'],$wechat['tagid']);
        if($res['errcode'] > 0){
            Log::record(json_encode(['swoole_server_error_data'=>$wechat]), 'elk_more_info','wechat_tag');
            Log::record(json_encode(['swoole_server_error_return'=>$res]), 'elk_more_info','wechat_tag');
            //Log::save();
        }
        return $res;
    }
}